package malware.esgi.moncef.mymalware;

import android.Manifest;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private int MY_PERMISSIONS_REQUEST_SMS_RECEIVE = 10;
    private static MainActivity ins;
    private Button savetheMsg,destorytheMsg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        destorytheMsg = findViewById(R.id.destroyMsg);
        savetheMsg = findViewById(R.id.saveMsg);

        savetheMsg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SmsReceiver.broadcastMsg("save");
                Toast.makeText(getApplicationContext(),"Sauvegardé", Toast.LENGTH_LONG);
            }
        });

        destorytheMsg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SmsReceiver.broadcastMsg("delete");
                Toast.makeText(getApplicationContext(),"Supprimé", Toast.LENGTH_LONG);


            }
        });
        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.RECEIVE_SMS},
                MY_PERMISSIONS_REQUEST_SMS_RECEIVE);
        ins = this;

    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == MY_PERMISSIONS_REQUEST_SMS_RECEIVE) {
        }
    }


    public static MainActivity  getInstace(){
        return ins;
    }

    public void updateTheTextView(final String t) {
        MainActivity.this.runOnUiThread(new Runnable() {
            public void run() {
                TextView textV1 = (TextView) findViewById(R.id.smsMessage);
                textV1.setText(t);
            }
        });
    }
}
